package kcms.assignment.service.impl;

import java.util.Arrays;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import kcms.assignment.dao.AssignmentDao;
import kcms.assignment.service.AssignmentService;
import kcms.db.Assign;
import kcms.db.Assignment;
import kcms.db.Assignmentcontent;
import kcms.db.Assignmentscore;
@Service
public class AssignmentServiceImpl implements AssignmentService{
	
	@Resource
	private AssignmentDao assignmentdao;
	@Resource
	private Assignmentscore assignmentscore;
	public AssignmentDao getAssignmentdao() {
		return assignmentdao;
	}

	public void setAssignmentdao(AssignmentDao assignmentdao) {
		this.assignmentdao = assignmentdao;
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public boolean saveNewTask(Assignment as){
		return assignmentdao.saveNewTask(as);
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public List<Assign> getAllAssignBySid(String id){
		return assignmentdao.getAllAssignBySid(id);
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public Assign getAssignByAid(String aid){
		return assignmentdao.getAssignByAid(aid);
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public Assignmentcontent getAssignmentcontentByAid(Integer assignmentid){
		return assignmentdao.getAssignmentcontentByAid(assignmentid);
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public boolean deleteAssignmentcontent(Assignmentcontent asc){
		return assignmentdao.deleteAssignmentcontent(asc);
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public boolean saveContentRecord(Integer assignmentid, String docFileName,
			String filename){
		return assignmentdao.saveContentRecord(assignmentid, docFileName,filename);
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public List<Assign> getAllAssignByCidCsn(String cid, String csn){
/*		int flag=0;
		List<Assign> templ = assignmentdao.getAllAssignByCidCsn(cid, csn);
		Assign[] temp = (Assign[])templ.toArray(new Assign[templ.size()]);
		for(int i=0;i<temp.length;i++){
			for(int j=i+1;j<temp.length;j++){
				if(temp[i].getAssignmentsn().intValue()==temp[j].getAssignmentsn().intValue()){
					temp[j].setAssignmentsn(-1);
					flag++;
				}
			}
		}
		Assign[] tempa = new Assign[templ.size()-flag];
		int t=0;
		for(int p=0;p<temp.length;p++){
			if(temp[p].getAssignmentsn().intValue()!=-1){
				tempa[t]=temp[p];
				t++;
			}		
		}
		return Arrays.asList(tempa);*/
	return assignmentdao.getAllAssignByCidCsn(cid, csn);
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public List<Assign> getAllAssignByCidCsnAsn(String cid, String csn,
			String assignmentsn){
		return assignmentdao.getAllAssignByCidCsnAsn(cid,csn,assignmentsn);
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public boolean deleteAssign(String assignmentsn){
		return assignmentdao.deleteAssign(assignmentsn);
	}
	
	
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public List<Assign> getAllAssignByAsn(String assignmentsn){
		return assignmentdao.getAllAssignByAsn( assignmentsn);
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public Assign getAssignBySidAsn(String sid, String asn){
		return assignmentdao.getAssignBySidAsn(sid, asn);
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public boolean saveNewScore(Integer assignmentid, String score, String pingyu){
		assignmentscore.setAssignmentid(assignmentid);
		assignmentscore.setPingyu(pingyu);
		assignmentscore.setScore(Double.parseDouble(score));
		assignmentscore.setStatus(true);
		return assignmentdao.saveNewScore(assignmentscore);
	}

	public Assignmentscore getAssignmentscore() {
		return assignmentscore;
	}

	public void setAssignmentscore(Assignmentscore assignmentscore) {
		this.assignmentscore = assignmentscore;
	}
	
}
